package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName BaseTrademarkController
 * @Description 此类描述:品牌
 * @Author dangchen
 * @DateTime 2022-10-31 22:51
 * @Version 1.0
 */
@RestController
@RequestMapping("admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;

    /**
     * 获取品牌属性
     * @return
     */
    @GetMapping("getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }

    /**
     * 分页显示
     * @param page 页数
     * @param limit 每页条数
     * @return
     */
    @GetMapping("{page}/{limit}")
    public Result BaseTrademarkList(@PathVariable Long page,
                                    @PathVariable Long limit){
        Page<BaseTrademark> trademarkPage = new Page<>(page,limit);
        //分页查询；  需要引入分页插件
        Page<BaseTrademark> list = baseTrademarkService.page(trademarkPage);
        return Result.ok(list);
    }

    /**
     * 增
     * @param baseTrademark
     * @return
     */
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    /**
     * 删
     * @param id
     * @return
     */
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * 改
     * @param baseTrademark
     * @return
     */
    @PutMapping("update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 按id查询
     * @param id
     * @return
     */
    @GetMapping("get/{id}")
    public Result getById(@PathVariable Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }
}
